﻿@{
    ViewBag.Title = "校友管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!-- BEGIN MAIN CONTENT -->
<section class="wrapper site-min-height">
    <!-- BEGIN ROW  -->
    <div class="row">
        <div class="col-lg-12">
            <section class="panel">
                <header class="panel-heading">
                    <span class="label label-primary">校友名录</span>
                    <span class="tools pull-right"></span>
                </header>
                <div class="panel-body">
                    <div class="clearfix">
                        <a class="btn btn-primary" id="" target="_self" href="/Alumni/Edit">
                            增加记录
                        </a>
                         <button class="btn btn-success" data-toggle="dropdown" id="Export">
                            导出到Excel
                        </button>
                    </div>
                    <div class="adv-table">
                        <table class="display table table-bordered table-striped" id="myTable">
                            <thead>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <!-- END ROW  -->
</section>


<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">确认信息</h4>
            </div>
            <div class="modal-body">
                确认要删除该校友吗？
            </div>
            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                <button class="btn btn-warning" type="button" id="submit">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/bootstrap-table.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- Latest compiled and minified Locales -->
<script>
   
    function Del(id) {
        var data = { SerialNumber: id };
        $.post("/Alumni/Delete", data, function (msg) {
            if (msg.IsSuccess) {
                //刷新表格数据
                $("#myTable").bootstrapTable('refresh', {
                    url: '/Alumni/QueryList',
                    silent: true
                });
            }
            console.log(msg);
        })
    }

    function exportExcel() {
        var data = {
            searchText: ''
        };
        window.top.open("ExportExcel?searchText=");
    }

    $(function () {

        $("#Export").click(function () {
            exportExcel()
        });

        window.operateEvents = {
            'click .btn-primary': function (e, value, row, index) {
                location
            }
        };

        $("#myTable").bootstrapTable({
            url: '/Alumni/QueryList',   //数据绑定，后台的数据从jsp代码
            search: true,
            striped: true,
            uniqueId: "SerialNumber",
            pageList: [5, 10, 15, 20, 25],
            pageNumber: 1,
            sidePagination: "server",
            pagination: true,
            height: 'auto',
            columns: [
            {
                field: 'SerialNumber',
                title: '序号',
                visible: false
            }, {
                field: 'RealName',
                title: '姓名',
                formatter: function (value, row) {
                    return '<a target="_blank" href="/Alumni/Preview?id=' + row.SerialNumber + '">' + value + '</a>';
                }
            }, {
                field: 'Gender',
                title: '性别'
            }, {
                field: 'Phone',
                title: '手机号'
            }, {
                field: 'Address',
                title: '联系地址',
            }, {
                field: 'GraduationDate',
                title: '毕业时间'
            },
            {
                field: 'Opt',
                title: '操作',
                align: 'center',
                events: operateEvents,
                formatter: function (value, row, index) {
                    return [
                        '<a id="add-sticky" class="btn btn-primary  btn-xs" target="_blank" href="/Alumni/Modify?id=' + row.SerialNumber + '"><i class="fa fa-pencil"></i></a>',
                        '<button  onclick="javascript:Del(' + row.SerialNumber + ')" class="btn btn-danger btn-xs"><i class="fa fa-times"></i></button>'
                    ].join(' ');
                }
            }],
            queryParamsType: "undefined",
            queryParams: function queryParams(params) {   //设置查询参数  
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    searchText: params.searchText
                };
                return param;
            },
            onLoadSuccess: function () {  //加载成功时执行  
                console.log("加载成功");
            },
            onLoadError: function () {  //加载失败时执行  
                console.log("加载数据失败", { time: 1500, icon: 2 });
            }
        })
    })
</script>
